/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.oea.hibernate.entities;

import com.oea.hibernate.utilities.HibernateUtil;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author unnati
 */
@Table(name = "topics")
@Entity
public class Topic extends AbstractEntity {

    @GeneratedValue

    @Column(name = "id")
    @Id
    protected Long id;

    @Column(name = "name")
    protected String name;

    @Column(name = "subid")
    protected Long subid;
    
    @Transient
    protected Subject subject;

    public Subject getSubject() {
        return subject;
    }

    public void setSubject( ) {
        this.subject = (Subject) new Subject().getById(subid);
    }
    

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getSubid() {
        return subid;
    }

    public void setSubid(Long subid) {
        this.subid = subid;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public static List<Topic> getAllTopicsBySubjectId(long subid) 
    {

       
        List<Topic> arr_list_topic = null;

        try 
        {
            Session s=HibernateUtil.getSessionFactory().openSession();
            Query q=s.createQuery("from Topic where subid = "+subid+"");
            arr_list_topic=q.list();
            
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        return arr_list_topic;

    }

     

}
